import scrapy
import json
from map.items import MapItem

class MaplistSpider(scrapy.Spider):
    name = 'mapList'
    # allowed_domains = ['http://www.jjz365.cn/XMap/GetDistrictData']
    url = 'http://www.jjz365.cn/XMap/GetDistrictData'

    def start_requests(self):
        area = ['海淀区', '朝阳区', '东城区', '西城区','丰台区','昌平区','通州区','顺义区','平谷区','房山区','大兴区','延庆区','石景山区','怀柔区','密云区','门头沟区']
        for val in area:
            yield scrapy.FormRequest(
                url=self.url,
                formdata={'district': val},
                callback=self.parse
            )


    def parse(self, response):
        item = MapItem()
        listData =json.loads(response.text)
        print(listData)
        # result = json.loads(listData)
        # print(result)
        # for val in result:
        #     item['Longitude'] = val['Longitude']
        #     item['District'] = val['District']
        #     yield item

